<?php
if(!defined('IN_ORA')) {
	exit('Access Denied');
}
$GLOBALS['__page_cache__'] = true;
$act = $GLOBALS['act'] ==""?"index":$GLOBALS['act'];
$GLOBALS['tpl']->assign('act',$act);
/*** Tag ***/
if($act == "v"){
	$key = clear_html($GLOBALS['_param']['key']);
	$key = preg_replace('/\'|\"|\=|update|select|delete|truncate|insert|drop|exec|eval|\$|\{|\}|\(|\)/i','',$key);
	if($key==""){
		redirect("index-index");
	}
	if(!$GLOBALS['tpl']->isCached("tag-v-key-$key")){
		/** 站点信息 **/
		$GLOBALS['tpl']->assign('sinfo',$GLOBALS['db']->getOne('select * from '.tn('info').' order by Id asc limit 1'));

		/** 导航信息 **/
		$GLOBALS['tpl']->assign('navs',$GLOBALS['db']->getAll('select * from '.tn('nav').' order by nav_sort asc limit 6'));

		/** 产品信息 **/
		import("lib.cat");
		$cates = cat_lib::getSubChild(0,2,' and cat_type=1');
		$GLOBALS['tpl']->assign('cates',$cates);
		/** 当前位置 **/
		$local = array();
		$local[] = array('url'=>get_url(true),'text'=>'产品搜索_'.$key);
		$GLOBALS['tpl']->assign('local',$local);
		/** 专题标签 **/
		$GLOBALS['tpl']->assign('tags',$GLOBALS['db']->getAll('select * from '.tn('tags').' where tag_type=1 group by tag_name order by Id desc'));

		/******** Search ********/
		$GLOBALS['tpl']->assign('keywords',$key);
		$sql = "select * from ".tn('tags')." where tag_name = '$key'";
		$tag = array();
		$q = $GLOBALS['db']->query($sql);
		while ($row = $GLOBALS['db']->fetch_array($q)) {
			if(intval($row['tag_type']) === 1){//产品
				$sql  = "select op.*,oc.cat_name,oc.path,ocnt.content,opa.attr from ".tn('product')." op left join ".tn('cat')." oc ";
				$sql .=" on oc.Id = op.cat_id left join ".tn('content')." ocnt on ocnt.fk_id = op.Id ";
				$sql .=" left join ".tn('pattr')." opa on opa.p_id = op.Id where ocnt.ctype = 1 and op.Id = ".$row['fk_id'];
				$pro = $GLOBALS['db']->getOne($sql);
				if($pro){
					$tag['pros'][] = $pro;
				}
			}else{
				$sql = "select oa.*,oc.cat_name,oc.path,octont.content from ".tn('article')." oa ";
				$sql.= "left join ".tn('cat')." oc on oa.cat_id = oc.Id ";
				$sql.= "left join ".tn('content')." octont on octont.fk_id = oa.Id ";
				$sql.= " where octont.ctype = 0 and oa.id= ".$row['fk_id'];
				$art = $GLOBALS['db']->getOne($sql);
				if($art){
					$tag['arts'][] = $art;
				}
			}
		}
		$GLOBALS['tpl']->assign('tag',$tag);
	}

	$GLOBALS['tpl']->display("tag.html");
}


?>